package com.fanxuankai.ksql.function.udf.string;

import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;
import io.confluent.ksql.function.udf.UdfParameter;
import org.apache.commons.lang3.StringUtils;

/**
 * 银行卡号脱敏
 * 6227 0383 3938 3938 393 脱敏结果: 6227 **** **** ***8 393*
 *
 * @author sixiaojie
 * @date 2022-06-25-15:22
 */
@UdfDescription(name = "bank_card_mask", description = "bank_card_mask", author = "sixiaojie")
public class BankCardMask {

    @Udf
    public String calc(@UdfParameter("val") String bankCard) {
        if ((bankCard == null || "".equals(bankCard))) {
            return "";
        }

        return StringUtils.left(bankCard, 4).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(bankCard, 4), StringUtils.length(bankCard), "*"), "***"));

    }

}
